#include "BaseType.h"
#include "Tracer.h"

using namespace libemb;
/**
 * 外观模式：
 * 1. 外观模式封装了多个子系统的交互，使得客户端不用关注与子系统的交互。
 * 2. 客户端仍旧可以调用子系统的接口。
 * 适用场景：
 * 1. 子系统交互比较复杂，客户端不愿过多关注子系统。
 * 2. 
 **/

struct CustomerInfo{
    std::string address;
    std::string phoneNumber;
};

//美团系统
class MeiTuan{
DECL_CLASSNAME(MeiTuan)
public:
    void getOrder(int orderID, std::string clerkName)
    {
        TRACE_INFO_CLASS("start order: %d, delivery clerk: %s",orderID, CSTR(clerkName));
    }
    CustomerInfo getCustomerInfo(int orderID)
    {
        //在美团系统中根据订单号查找客户信息
        CustomerInfo info{"xx Floor, xx Building, xx Road","13987654321"};
        return info;
    }
    void finishOrder(int orderID)
    {
         TRACE_INFO_CLASS("finish order: %d, payment:%d",orderID, 5);
    }
};

//导航系统
class Navigation{
DECL_CLASSNAME(Navigation)
public:
    void navigate(std::string destination)
    {
        //根据目的地址，规划路径并实施导航
        TRACE_INFO_CLASS("navigation to: %s",CSTR(destination));
    }
};

//配送
class Delivery{
DECL_CLASSNAME(Delivery)
public:
    Delivery()
    {
        m_meituan = std::make_unique<MeiTuan>();
        m_navigation = std::make_unique<Navigation>();
    }
    void deliver(int orderID)//外卖配送
    {
        m_meituan->getOrder(orderID,"SuperMan");
        auto info = m_meituan->getCustomerInfo(orderID);
        m_navigation->navigate(info.address);
        m_meituan->finishOrder(orderID);
    }
private:
    std::unique_ptr<MeiTuan> m_meituan;
    std::unique_ptr<Navigation> m_navigation;
};

int main()
{
    Tracer::getInstance().setLevel(TRACE_LEVEL_DBG);
	Tracer::getInstance().addSink(std::make_shared<STDSink>()).start();
    Delivery delivery;
    delivery.deliver(8888);
    return RC_OK;
}